package com.hairline.controller;

import com.hairline.bean.bo.WxCartCheckedBo;
import com.hairline.bean.bo.WxCartUpdateBo;
import com.hairline.bean.vo.BaseRespVo;
import com.hairline.bean.vo.WxCartIndexVo;
import com.hairline.service.WxCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by fenglin on 2020/9/5 5:05 AM
 */
@RestController
@RequestMapping("wx/cart")
public class WxCartController {

    @Autowired
    WxCartService wxCartService;

    //没测试，在点击商品时，会用到这个接口
    @GetMapping("goodscount")
    public BaseRespVo cartGoodscount(){
        long counts = wxCartService.cartGoodscount();
        return BaseRespVo.ok(counts);
    }
    //请求 {"goodsId":1006051,"number":1,"productId":12}
    //返回包含购物车商品数量的json数据
    //TODO
//    @PostMapping("add")
//    public BaseRespVo cartAdd(CartAddBoFl cartAddBoFl){
//        long counts = wxCartServiceFl.cartAdd();
//        return BaseRespVo.ok(counts);
//
//    }

    @GetMapping("index")
    public BaseRespVo cartIndex(){
        WxCartIndexVo wxCartIndexVo = wxCartService.cartIndex();
        return BaseRespVo.ok(wxCartIndexVo);
    }

    @PostMapping("update")
    //TODO 判断是否超出库存
    public BaseRespVo cartUpdate(@RequestBody WxCartUpdateBo wxCartUpdateBo){
        int code = wxCartService.cartUpdate(wxCartUpdateBo);
        if(code == 200){
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("已超出库存量");
    }

    @PostMapping("checked")
    //返回的数据是当前购物车的数据
    public BaseRespVo cartChecked(@RequestBody WxCartCheckedBo wxCartCheckedBo){
        WxCartIndexVo wxCartIndexVo = wxCartService.cartChecked(wxCartCheckedBo);
        return BaseRespVo.ok(wxCartIndexVo);
    }

}
